# -*- coding: utf-8 -*-
import os
from  datetime  import timedelta
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

import logging

class Config(object):
    # 日志文件和数据库文件保存的路径
    DATA_DIR = './data'
    if os.path.exists(os.path.join(basedir, DATA_DIR)) is False:
        os.mkdir(os.path.join(basedir, DATA_DIR))
        
    SECRET_KEY = '^753*&FdFS#4D'
    WTF_CSRF_SECRET_KEY = os.environ.get('WTF_CSRF_SECRET_KEY') or 'you-will-never-guess'
    
    SESSION_TYPE = 'filesystem'
    SESSION_FILE_DIR = os.path.join(basedir, f'{DATA_DIR}/flask_sessions')
    SESSION_LIFETIME = timedelta(minutes=1)
    
    # Email config
    MAIL_SERVER = 'smtp.qq.com'
    MAIL_PORT = 465
    MAIL_USE_SSL = False
    MAIL_USERNAME = ''
    MAIL_PASSWORD = ''
    
    MAIL_SUBJECT_PREFIX = '[Flask-Todo-App]' # 邮件主题前缀
    MAIL_SENDER = 'Flask-Todo-App Admin <<EMAIL>>' # 邮件发送者
    
    # Babel config
    BABEL_DEFAULT_LOCALE = 'zh'
    BABEL_DEFAULT_TIMEZONE = 'CST'
    
    SQLALCHEMY_RECORD_QUERIES = True
    SQLALCHEMY_TRACK_MODIFICATIONS = False # 动态追踪修改设置，如未设置只会提示警告    
    SQLALCHEMY_ECHO = False # 查询时是否显示原始SQL语句       
    # SQLALCHEMY_POOL_SIZE=10# 数据库连接池的大小
    # SQLALCHEMY_POOL_TIMEOUT=10#指定数据库连接池的超时时间
    # 控制在连接池达到最大值后可以创建的连接数。当这些额外的 连接回收到连接池后将会被断开和抛弃。
    # SQLALCHEMY_MAX_OVERFLOW=2
    
    # bootstrap本地配置
    BOOTSTRAP_SERVE_LOCAL = True # 设置为使用本地资源
    
    # TODO 配置日志等级 
    # FATAL/CRITICAL = 致命的，危险的     Critical 
    # ERROR = 错误
    # WARNING = 警告
    # INFO = 信息
    # DEBUG = 调试
    # NOTSET = 没有设置
    LOG_LEVEL = logging.DEBUG
    LOG_DIR = f'{DATA_DIR}/logs'
    if os.path.exists(os.path.join(basedir, LOG_DIR)) is False:
        os.mkdir(os.path.join(basedir, LOG_DIR))
    LOG_FILE = os.path.join(basedir, LOG_DIR + '/log.log')


class DevelopmentConfig(Config):
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, f'{Config.DATA_DIR}/app.sqlite')  # NOQA 
    

class ProductionConfig(Config):
    SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, f'{Config.DATA_DIR}/app.sqlite')  # NOQA

config = {
    'default': DevelopmentConfig,
    'development': DevelopmentConfig,
    'production': ProductionConfig,
}
